<?php
namespace app\model;
use app\utils\CamlHump;
use think\facade\Db;
use think\Model;
class SysAccount extends BaseModel
{
    protected $convertNameToCamel = true;
    protected $name = 'sys_account';

    static function  build($data)
    {
        $emptyData = [];


        //是int类型的 BIGINT
        $emptyData['id']= $data['id' ] ?? 0;






        //是 VARCHAR 类型的 VARCHAR
        $emptyData['userName']= $data['userName' ] ?? '';





        //是 VARCHAR 类型的 VARCHAR
        $emptyData['passWord']= $data['passWord' ] ?? '';




        //是int类型的 INT
        $emptyData['loginNum']= $data['loginNum' ] ?? 0;





        //是int类型的 TINYINT
        $emptyData['state']= $data['state' ] ?? 0;





        //是int类型的 TINYINT
        $emptyData['onlieState']= $data['onlieState' ] ?? 0;





        //是int类型的 TINYINT
        $emptyData['isAdmin']= $data['isAdmin' ] ?? 0;





        //是int类型的 TINYINT
        $emptyData['ipState']= $data['ipState' ] ?? 0;






        //是 VARCHAR 类型的 VARCHAR
        $emptyData['ip']= $data['ip' ] ?? '';






        //是 VARCHAR 类型的 DATETIME
        $emptyData['lastLoginTime']= $data['lastLoginTime' ] ?? date("Y-m-d H:i:s", time());




        //是 VARCHAR 类型的 VARCHAR
        $emptyData['lastIp']= $data['lastIp' ] ?? '';




        //是int类型的 TINYINT
        $emptyData['tenantType']= $data['tenantType' ] ?? 0;





        //是int类型的 BIGINT
        $emptyData['tenantId']= $data['tenantId' ] ?? 0;





        //是int类型的 TINYINT
        $emptyData['delState']= $data['delState' ] ?? 0;






        //是 VARCHAR 类型的 VARCHAR
        $emptyData['addUser']= $data['addUser' ] ?? '';




        //是int类型的 BIGINT
        $emptyData['addUserId']= $data['addUserId' ] ?? 0;







        //是 VARCHAR 类型的 DATETIME
        $emptyData['addTime']= $data['addTime' ] ?? date("Y-m-d H:i:s", time());




        //是 VARCHAR 类型的 VARCHAR
        $emptyData['editUser']= $data['editUser' ] ?? '';




        //是int类型的 BIGINT
        $emptyData['editUserId']= $data['editUserId' ] ?? 0;







        //是 VARCHAR 类型的 DATETIME
        $emptyData['lastEditTime']= $data['lastEditTime' ] ?? date("Y-m-d H:i:s", time());



        //是int类型的 SMALLINT
        $emptyData['serverNumber']= $data['serverNumber' ] ?? 0;







        //是 VARCHAR 类型的 DATETIME
        $emptyData['delTime']= $data['delTime' ] ?? date("Y-m-d H:i:s", time());

        return $emptyData;
    }
    static function createQuery($queryData)
    {
        $query = Db::table('sys_account');

        //是int类型的 BIGINT
        if(isset($queryData['id'])&&$queryData['id']>=0){
            $query->where('id', $queryData['id']);
        }



        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['userName'])&&$queryData['userName']!=''){
            $query->where('user_name', $queryData['userName']);
        }



        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['passWord'])&&$queryData['passWord']!=''){
            $query->where('pass_word', $queryData['passWord']);
        }


        //是int类型的 INT
        if(isset($queryData['loginNum'])&&$queryData['loginNum']>=0){
            $query->where('login_num', $queryData['loginNum']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['state'])&&$queryData['state']>=0){
            $query->where('state', $queryData['state']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['onlieState'])&&$queryData['onlieState']>=0){
            $query->where('onlie_state', $queryData['onlieState']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['isAdmin'])&&$queryData['isAdmin']>=0){
            $query->where('is_admin', $queryData['isAdmin']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['ipState'])&&$queryData['ipState']>=0){
            $query->where('ip_state', $queryData['ipState']);
        }



        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['ip'])&&$queryData['ip']!=''){
            $query->where('ip', $queryData['ip']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['lastLoginTime'])&&$queryData['lastLoginTime']!=''){
            $query->where('last_login_time', $queryData['lastLoginTime']);
        }


        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['lastIp'])&&$queryData['lastIp']!=''){
            $query->where('last_ip', $queryData['lastIp']);
        }


        //是int类型的 TINYINT
        if(isset($queryData['tenantType'])&&$queryData['tenantType']>=0){
            $query->where('tenant_type', $queryData['tenantType']);
        }



        //是int类型的 BIGINT
        if(isset($queryData['tenantId'])&&$queryData['tenantId']>=0){
            $query->where('tenant_id', $queryData['tenantId']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['delState'])&&$queryData['delState']>=0){
            $query->where('del_state', $queryData['delState']);
        }



        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['addUser'])&&$queryData['addUser']!=''){
            $query->where('add_user', $queryData['addUser']);
        }


        //是int类型的 BIGINT
        if(isset($queryData['addUserId'])&&$queryData['addUserId']>=0){
            $query->where('add_user_id', $queryData['addUserId']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['addTime'])&&$queryData['addTime']!=''){
            $query->where('add_time', $queryData['addTime']);
        }


        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['editUser'])&&$queryData['editUser']!=''){
            $query->where('edit_user', $queryData['editUser']);
        }


        //是int类型的 BIGINT
        if(isset($queryData['editUserId'])&&$queryData['editUserId']>=0){
            $query->where('edit_user_id', $queryData['editUserId']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['lastEditTime'])&&$queryData['lastEditTime']!=''){
            $query->where('last_edit_time', $queryData['lastEditTime']);
        }

        //是int类型的 SMALLINT
        if(isset($queryData['serverNumber'])&&$queryData['serverNumber']>=0){
            $query->where('server_number', $queryData['serverNumber']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['delTime'])&&$queryData['delTime']!=''){
            $query->where('del_time', $queryData['delTime']);
        }

        $query->where('del_state', 1);

        return   $query;

    }

    static function findOne($id){
        $query=Db::table("sys_account")->where("id", $id);
        $one = CamlHump::toCamlObj($query->find());
        return $one;
    }

    static function addPlus($data){
        $addWidthDefault = static::build($data);
        $result = static::create($addWidthDefault);
        return $result;
    }
    static function updatePlus($data, $id)
    {
        $result = static::update($data, ['id' => $id]);
        return $result;
    }
    static function deletePlus($id)
    {
        $result = static::destroy($id);
        return $result;
    }
}